package cn.org.intelli.lims.o2oa.constant;

import java.util.ArrayList;
import java.util.List;
import javax.persistence.AttributeConverter;
import lombok.AllArgsConstructor;
import lombok.Getter;
import xyz.erupt.annotation.fun.ChoiceFetchHandler;
import xyz.erupt.annotation.fun.VLModel;

@Getter
@AllArgsConstructor
public enum MaterialOpStatus {
  RUNNING("操作中"),
  FINISH("操作完成");
  private final String desc;

  public static class Convert implements AttributeConverter<MaterialOpStatus, String> {

    @Override
    public String convertToDatabaseColumn(MaterialOpStatus status) {
      return status == null ? null : status.name();
    }

    @Override
    public MaterialOpStatus convertToEntityAttribute(String status) {
      for (MaterialOpStatus value : MaterialOpStatus.values()) {
        if (status.equals(value.name())) {
          return value;
        }
      }
      throw new RuntimeException("Unknown database value: " + status);
    }
  }

  public static class Handler implements ChoiceFetchHandler {

    @Override
    public List<VLModel> fetch(String[] params) {
      List<VLModel> list = new ArrayList<>();
      for (MaterialOpStatus value : MaterialOpStatus.values()) {
        list.add(new VLModel(value.name(), value.getDesc()));
      }
      return list;
    }
  }
}
